package data.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import data.dao.MyJdbcQuery;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * Created by Administrator on 2016/11/3.
 */
@Configuration
@ComponentScan
@EntityScan("data.entity")
@EnableJpaRepositories("data.dao")
@Order(-10)
public class DataBaseConfiguration {

    private Logger logger = Logger.getLogger(getClass().getName());;



    @Bean
    @Qualifier("dataSource")
    public DataSource dataSource() {
        logger.info("dataSource() invoked");
        DataSource dataSource = new ComboPooledDataSource("test");
        return dataSource;
    }

    @Bean
    public JdbcTemplate jdbcTemplate(){
        return new JdbcTemplate(dataSource());
    }
    @Bean
    public MyJdbcQuery myJdbcQuery(){
        return new MyJdbcQuery(jdbcTemplate());
    }
}